package com.jlwl.houseservice.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jlwl.houseservice.common.Result;
import com.jlwl.houseservice.entity.Review;
import com.jlwl.houseservice.service.ReviewService;
import com.jlwl.houseservice.vo.ReviewQueryVO;
import com.jlwl.houseservice.vo.ReviewReplyVO;
import com.jlwl.houseservice.vo.ReviewStatsVO;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员评价控制器
 */
@RestController
@RequestMapping("/admin/reviews")
@PreAuthorize("hasRole('ADMIN')")
public class AdminReviewController {

    @Autowired
    private ReviewService reviewService;

    /**
     * 获取评价列表
     */
    @GetMapping
    public Result<Page<Review>> list(ReviewQueryVO queryVO) {
        Page<Review> page = reviewService.pageList(queryVO);
        return Result.success(page);
    }

    /**
     * 回复评价
     */
    @PutMapping("/{id}/reply")
    public Result<Void> reply(@PathVariable Integer id, @Valid @RequestBody ReviewReplyVO replyVO) {
        boolean success = reviewService.replyReview(id, replyVO);
        if (!success) {
            return Result.error("回复评价失败");
        }
        return Result.success();
    }

    /**
     * 更新评价状态
     */
    @PutMapping("/{id}/status")
    public Result<Void> updateStatus(@PathVariable Integer id, @RequestParam Integer status) {
        boolean success = reviewService.updateReviewStatus(id, status);
        if (!success) {
            return Result.error("更新评价状态失败");
        }
        return Result.success();
    }

    /**
     * 获取服务评价统计
     */
    @GetMapping("/stats/service/{serviceId}")
    public Result<ReviewStatsVO> getServiceReviewStats(@PathVariable Integer serviceId) {
        ReviewStatsVO statsVO = reviewService.getServiceReviewStats(serviceId);
        return Result.success(statsVO);
    }

    /**
     * 获取员工评价统计
     */
    @GetMapping("/stats/employee/{employeeId}")
    public Result<ReviewStatsVO> getEmployeeReviewStats(@PathVariable Integer employeeId) {
        ReviewStatsVO statsVO = reviewService.getEmployeeReviewStats(employeeId);
        return Result.success(statsVO);
    }
} 